package com.shuma.userservice.controller;


import com.shuma.userservice.domain.dto.LoginDTO;
import com.shuma.userservice.domain.dto.RegisterDTO;
import com.shuma.userservice.domain.dto.ResetPasswordDTO;
import com.shuma.userservice.domain.dto.UpdateUserDTO;
import com.shuma.userservice.domain.pojo.Users;
import com.shuma.userservice.domain.vo.UserLoginVO;
import com.shuma.userservice.service.UsersService;
import io.swagger.annotations.Api;
import io.swagger.annotations.ApiOperation;
import lombok.RequiredArgsConstructor;
import org.springframework.http.ResponseEntity;
import org.springframework.web.bind.annotation.*;

@Api(tags = "用户相关接口")
@RestController
@RequestMapping("/user")
@RequiredArgsConstructor
public class UserController {

    private final UsersService usersService;

    @ApiOperation("用户注册接口")
    @PostMapping("/register")
    public ResponseEntity<Void> register(RegisterDTO dto) {
        usersService.register(dto);
        return ResponseEntity.ok().build();
    }

    @ApiOperation("用户登录接口")
    @PostMapping("/login")
    public UserLoginVO login(LoginDTO dto) {
        return usersService.login(dto);
    }

    @ApiOperation("用户查询接口")
    @GetMapping("/{userId}")
    public Users getUser(@PathVariable("userId") Long userId) {
        return usersService.getUser(userId);
    }

    @ApiOperation("修改用户信息接口")
    @PutMapping("/{userId}")
    public Users updateUser(@PathVariable("userId") Long userId, UpdateUserDTO dto) {
        return usersService.updateUser(userId, dto);
    }

    @ApiOperation("重置密码接口")
    @PostMapping("/reset-password")
    public Users resetPassword(ResetPasswordDTO dto) {
        return usersService.resetPassword(dto); // 权限逻辑也在 Service 内判断

    }

}
